﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ERPStore.Extensions;

using CloudSoft.Extensions;

namespace ERPStore.Web.Services
{
	public class ModelMetatdataRegistrationService : IModelMetadataRegistrationService
	{
		public ModelMetatdataRegistrationService()
		{
			List = new List<ModelMetadata.ModelMetaData>();
			// Register(new ModelMetadata.RegistrationUserMetadataDefinition());
			// Register(new ModelMetadata.AddressMetadataDefinition());
			// Register(new ModelMetadata.ContactInfoMetadataDefinition());
		}

		#region IModelMetadataRegistrationService Members

		public void Register<TModel>(ModelMetadata.ModelMetadataDefinition<TModel> definition)
		{
			if (definition == null)
			{
				throw new ArgumentNullException();
			}

			// Suppression de toutes les definitions liées au model
			List.RemoveAll(i => i.ModelType == typeof(TModel));

			foreach (var item in definition.List)
			{
				List.Add(item);
			}
		}

		public IList<ModelMetadata.ModelMetaData> List { get ; private set; }

		#endregion
	}
}
